export default {
  state: {
    select_specification_show: false,//是否显示规格的选择框
    specifications: '',//规格列表
    now_specification_name: '',//当前规格名称
    now_specification_id: '',//当前规格ID
    now_specification_index: 0,//当前规格下标
    now_specification_price_normal: 0.00,//当前规格普通价
    now_specification_price_group: 0.00,//当前规格拼团价
    now_specification_stock: 0,//当前规格库存

    buy_num: 1,//购买数量

    goods_info: '',//商品信息

    banner: '',//banner数据
    banner_num: '',//banner数量
    banner_index: '',//banner当前下标

    goods_tag_list: '',//商品标签

    buy_price_normal: '0.00',//普通购买价格
    buy_price_group: "0.00",//拼团购买价格
    group_people_num: '1',//拼团人数
    buy_type: '',//group normal car

    is_collect: false,//是否收藏
    is_added_car: false,//是否已加入购物车

    show_discount_box: false, //是否显示优惠券

    show_share_group_view: false,//是否显示拼团分享页面

    // 拼团分享商品信息
    share_group_goods_info: '',
    share_group_type :'',
    share_group_ids:{},

    // 点击参团
    to_join_froup:false,
    group_order_spell_id:0,

    // 订单部分
    order_info:'',
    open_order_detail_view:false
  },
  mutations: {
    change_select_specification_show(state, tf) {
      state.select_specification_show = tf;
    },
    updata_goods_info(state, info) {
      // 更新商品信息
      state.goods_info = info;
      // 更新规格数据
      state.specifications = info.specification;
      // 更新banner数据
      state.banner = info.pics;
      state.first_banner = info.pics[0];
      state.last_banner = info.pics[info.pics.length - 1];
      state.banner_num = info.pics.length;
      state.banner_index = 1;
      // 更新商品标签
      var goods_tag_list = [];
      if (info.spell == 1) {
        goods_tag_list.push({
          tag_name: '拼团价'
        })
      }
      if (info.special_offer == 1) {
        goods_tag_list.push({
          tag_name: '社区精品'
        })
      }
      ;
      if (info.recom == 1) {
        goods_tag_list.push({
          tag_name: '优享特卖'
        })
      }
      state.goods_tag_list = goods_tag_list;
      // 更新默认购买价格
      state.buy_price_normal = info.specification[0].price
      state.buy_price_group = info.specification[0].spell_money
      // 更新拼团人数
      state.group_people_num = info.count;
      // 更新购买数量
      state.buy_num = 1;
    },
    change_specification(state, k) {
      k += "";
      if (k) {

        // 更改当前规格下标
        state.now_specification_index = k;
        // 更改当前规格名称
        state.now_specification_name = state.specifications[state.now_specification_index].rule;
        // 更改当前规格ID
        state.now_specification_id = state.specifications[state.now_specification_index].attrid;
        // 更改普通商品 当前规格价格
        state.now_specification_price_normal = state.specifications[state.now_specification_index].price;
        // 更改拼团商品 当前规格价格
        state.now_specification_price_group = state.specifications[state.now_specification_index].spell_money;
        // 更改当前规格数量
        state.now_specification_stock = state.specifications[state.now_specification_index].stock;
      }
    },
    change_buy_type(state, type) {
      state.buy_type = type;
    },
    add_buy_num(state) {
      state.buy_num++;
    },
    cut_buy_num(state) {
      if (state.buy_num <= 1) {
        return
      }
      state.buy_num--;

    },
    open_discount_view(state, tf) {
      state.show_discount_box = tf
    },
    open_share_group_view(state, tf) {
      state.show_share_group_view = tf
    },
    updata_share_group_goods_info(state, order_info) {
      state.share_group_goods_info = order_info;
    },
    updata_share_group_type(state,type){
      state.share_group_type = type
    },
    updata_share_group_sid(state,params){
      state.share_group_ids = params;
    },
    updata_to_join_froup(state,tf){
      state.to_join_froup = tf;
    },
    updata_group_order_spell_id(state,id){
      console.log("updata_group_order_spell_id-->"+id)
      state.group_order_spell_id = id;
    },
    updata_open_order_detail_view(state,tf){
      state.open_order_detail_view = tf;
    },
    updata_order_info(state,info){
      state.order_info = info;
    }
  }
}
